package main

import (
	"context"
	"fmt"
	"log"
	"net/http"

	"calculator/proto"
	"calculator/proto/protoconnect"

	"connectrpc.com/connect"
)

func main() {
	client := protoconnect.NewCalculatorServiceClient(
		http.DefaultClient,
		"http://localhost:8080",
	)

	// 测试加法
	resp, err := client.Calculate(
		context.Background(),
		connect.NewRequest(&proto.CalculateRequest{
			A:         10,
			B:         5,
			Operation: "+",
		}),
	)
	if err != nil {
		log.Fatalf("加法测试失败: %v", err)
	}
	fmt.Printf("10 + 5 = %v\n", resp.Msg.Result)

	// 测试减法
	resp, err = client.Calculate(
		context.Background(),
		connect.NewRequest(&proto.CalculateRequest{
			A:         10,
			B:         5,
			Operation: "-",
		}),
	)
	if err != nil {
		log.Fatalf("减法测试失败: %v", err)
	}
	fmt.Printf("10 - 5 = %v\n", resp.Msg.Result)

	// 测试乘法
	resp, err = client.Calculate(
		context.Background(),
		connect.NewRequest(&proto.CalculateRequest{
			A:         10,
			B:         5,
			Operation: "*",
		}),
	)
	if err != nil {
		log.Fatalf("乘法测试失败: %v", err)
	}
	fmt.Printf("10 * 5 = %v\n", resp.Msg.Result)

	// 测试除法
	resp, err = client.Calculate(
		context.Background(),
		connect.NewRequest(&proto.CalculateRequest{
			A:         10,
			B:         5,
			Operation: "/",
		}),
	)
	if err != nil {
		log.Fatalf("除法测试失败: %v", err)
	}
	fmt.Printf("10 / 5 = %v\n", resp.Msg.Result)
}
